import {Pic} from './Pic'
import {PicList} from '../FileList'

export default class PicLoader {
  constructor() {
    console.log('加载图片');
    this.pic = [];
    this.init();
  }

  init() {
    for (let file in PicList) {
      this.pic[file] = new Pic(PicList[file]);
    }
  }

  getItem(name) {
    for (let file in PicList) {
      if (PicList[file].includes(name)) {
        return this.pic[file];
      }
    }
  }

  getPic(name) {
    for (let file in PicList) {
      if (PicList[file].includes(name)) {
        return this.pic[file].getPic();
      }
    }
  }

  finished() {
    let all = this.pic.length;
    let fin = 0;
    for (let file in PicList) {
      if (this.pic[file].finished()) fin++;
    }
    return {'all': all, 'fin': fin}
  }
}
